<?php
class FPSFConfig
{
	public static $getFlashLink = '<a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a>';
	public static $contentFlexLinkDelim = '<hr/>';
	
	public static $defaultTitle = 'FPSFramework';
	public static $defaultSubTitleDelim = ' - ';
	
	public static $contentHasPHPCode = true;
}

class FPSF {
	
	public static function genHTMLPage($swf,$titel, $id, $content, $flashvar) {
		if ($content) {
			$content = $content . FPSFConfig::$contentFlexLinkDelim . FPSFConfig::$getFlashLink;
		} else {
			$content = FPSFConfig::$getFlashLink;
		} 
		if ($titel) {
			$titel = FPSFConfig::$defaultTitle . FPSFConfig::$defaultSubTitleDelim . $titel;
		} else {
			$titel = FPSFConfig::$defaultTitle;
		}
		return '
			<html lang="en">
				<head>
					<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
					<title>' . $titel . '</title>
					<style>
					body { margin: 0px; overflow:hidden }
					</style>
					<script type="text/javascript" src="swfobject.js"></script>
					<script type="text/javascript">
						var flashvars = {
								' . FPSF::genFlashVars($flashvar) . '
							};
						var params = { };
						var attributes = {
							id: "' . $id . '",
					  		name: "' . $id . '",
					  		bgcolor: "#FFFFFF",
					  		allowscriptaccess: "sameDomain",
					  		align: "middle",
					  		quality: "high"
							};
						swfobject.embedSWF("' . $swf . '", "myAlternateContent", "100%", "100%", "9.0.124", "expressInstall.swf", flashvars, params, attributes);
					</script>
				</head>
				
				<body>
					<div id="myAlternateContent">
						' . $content . '
					</div>
				</body>
			</html>';
	}
	
	private static function genFlashVars($var) {
		$keys = array_keys($var);
		$value = array_values($var);
		$merge = array();
		for ($i = 0; $i < count($var); $i++) {
			$merge[] = $keys[$i] . ': "' . $value[$i] . '"';
		}
		return implode(', ',$merge);
	}
	
	public static function convertToFlexContent($content) {
		$content = str_replace("\r\n","\n",$content);
		$content = preg_replace("/<h[1-6]>(.*?)<\/h[1-6]>/si",'<p><b>\\1</b></p>', $content);
		return $content;
	}
	
	public static function echoContent($content) {
		if (FPSFConfig::$contentHasPHPCode) {
			eval('?>' . $page);
		} else {
			echo $page;
		}
	}
}
?>